//
// package com.zhouxiaoge.antlr4.tool;
//
// import org.antlr.v4.runtime.CharStream;
// import org.antlr.v4.runtime.CharStreams;
// import org.antlr.v4.runtime.CommonTokenStream;
//
// import java.io.BufferedReader;
// import java.io.FileInputStream;
// import java.io.InputStream;
// import java.io.InputStreamReader;
//
// public class Calc {
//     public static void main(String[] args) throws Exception {
//         String inputFile = null;
//         if (args.length > 0) inputFile = args[0];
//         InputStream is = System.in;
//         if (inputFile != null) {
//             is = new FileInputStream(inputFile);
//         }
//
//         BufferedReader br = new BufferedReader(new InputStreamReader(is));
//         String expr = br.readLine();              // get first expression
//         int line = 1;                             // track input expr line numbers
//
//         ExprParser parser = new ExprParser(null); // share single parser instance
//         parser.setBuildParseTree(false);          // don't need trees
//
//         while (expr != null) {             // while we have more expressions
//             // create new lexer and token stream for each line (expression)
//             CharStream charStream = CharStreams.fromString(expr + "\n");
//             ExprLexer lexer = new ExprLexer(charStream);
//             lexer.setLine(line);           // notify lexer of input position
//             lexer.setCharPositionInLine(0);
//             CommonTokenStream tokens = new CommonTokenStream(lexer);
//             parser.setInputStream(tokens); // notify parser of new token stream
//             parser.stat();                 // start the parser
//             expr = br.readLine();          // see if there's another line
//             line++;
//         }
//     }
// }
